#!/usr/local/bin/python3
# -*- encoding: utf-8 -*-

import requests
from lxml import etree
import os

begin = 20631
end = 20735

len = end - begin + 1
num = 1

if not os.path.exists('videos'):
    os.mkdir('videos')

for i in range(begin, end):

    url = 'https://vs.leleketang.com/dat/ms/ph/k/video/' + str(i) + '.mp4'
    headers = {
        'User-Agent':
        'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/106.0.0.0 Safari/537.36 Edg/106.0.1370.34'
    }

    r = requests.get(url, headers=headers)

    if r.status_code == 200:

        html = etree.HTML(r.text)
        print(f'\n正在下载第{num}个视频...')

        with open(f'./videos/{num}.mp4', 'wb') as f:
            f.write(r.content)
            f.close()
    else:
        print(f'第{num}个视频不存在!')

    num += 1

    # 打印进度
    print(f'已完成{i-begin+1}/{len}!')
